<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else

    //Include the water test html file for form data
    include 'watertest.html';
    
   //Manual SQL COnnection
   $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
       
   mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
   
    $temp = $_POST['temp'];
    $dkh = $_POST['dkh'];
    $ph = $_POST['ph'];
    $amon = $_POST['amon'];
    $mag = $_POST['mag'];
    $nitrate = $_POST['nitrate'];
    $po4 = $_POST['po4'];
    $orp = $_POST['orp'];
    $cal = $_POST['cal'];
    $salinity = $_POST['salinity'];
    $sg = $_POST['sg'];
    
    //Date variables
    $day = $_POST['day'];
    $month = $_POST['month'];
    $year = $_POST['year'];
    
    //Function to make a valid date input if it has a space colon or period as a seperator
    $date = $year."-".$month."-".$day;

    //SQL Query to add water test
    $addtest = "insert into water_tests (user_id,test_date,temp,dkh,ph,amon,nitrate,po4,orp,cal,mag,salinity,sg) values(" . $_SESSION['uid'] . ",'$date','$temp','$dkh','$ph','$amon','$nitrate','$po4','$orp','$cal','$mag','$salinity','$sg')";

    //Execute Insert command
    if (!mysql_query($addtest,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "Water test added successfully!";

mysql_close($con);

?>